package com.juzi.lambda;

public class Introduce {
    public static void main(String[] args) {
        System.out.println("===============================\n" +
                "Lambda概述\n" +
                "\n" +
                " Lambda表达式是JDK 8开始后的一种新语法形式。\n" +
                " 作用：简化匿名内部类的代码写法。\n" +
                "------------------------------------------\n" +
                "Lambda表达式的简化格式\n" +
                "(匿名内部类被重写方法的形参列表) -> {\n" +
                "   被重写方法的方法体代码。\n" +
                "}\n" +
                "注：-> 是语法形式，无实际含义\n" +
                "\n" +
                "注意：Lambda表达式只能简化函数式接口的匿名内部类的写法形式\n" +
                "------------------------------------------\n" +
                "什么是函数式接口？\n" +
                "首先必须是接口、其次接口中有且仅有一个抽象方法的形式\n" +
                "------------------------------------------\n" +
                "体验Lambda表达式\n" +
                "public class LambdaDemo1 {\n" +
                "    public static void main(String[] args) {\n" +
                "\n" +
                "        goSwimming( new Swimming() {\n" +
                "            @Override\n" +
                "            public void swim() {\n" +
                "                System.out.println(\"铁汁, 我们去游泳吧~\");\n" +
                "            }\n" +
                "        } );\n" +
                "    }\n" +
                "\n" +
                "    public static void goSwimming(Swimming swimming) {\n" +
                "        swimming.swim();\n" +
                "    }\n" +
                "}\n" +
                "\n" +
                "\n" +
                "public class LambdaDemo1 {\n" +
                "    public static void main(String[] args) {\n" +
                "\n" +
                "        goSwimming( () -> {\n" +
                "\tSystem.out.println(\"铁汁, 我们去游泳吧~\") } );\n" +
                "        \n" +
                "    }\n" +
                "\n" +
                "    public static void goSwimming(Swimming swimming) {\n" +
                "        swimming.swim();\n" +
                "    }\n" +
                "}\n" +
                "\n" +
                "代码更少，关注点更加明确了\n" +
                "------------------------------------------\n" +
                "1、Lambda表达式的基本作用？\n" +
                "简化函数式接口的匿名内部类的写法。\n" +
                "2、Lambda表达式有什么使用前提？\n" +
                "必须是接口的匿名内部类，接口中只能有一个抽象方法\t\n" +
                "\n" +
                "------------------------------------------\n" +
                "Lambda表达式的省略写法（进一步在Lambda表达式的基础上继续简化）\n" +
                "参数类型可以省略不写。\n" +
                "如果只有一个参数，参数类型可以省略，同时()也可以省略。\n" +
                "如果Lambda表达式的方法体代码只有一行代码。可以省略大括号不写,同时要省略分号！\n" +
                "如果Lambda表达式的方法体代码只有一行代码。可以省略大括号不写。此时，如果这行代码是return语句，必须省略return不写，同时也必须省略\";\"不写\n" +
                "\n" +
                "");
    }
}
